home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / COMM / PCCP038.ARJ / MESSOUT.C < prev    next >
Text File  |  1992-07-09  |  3KB  |  173 lines

  1. /*    Copyright (C) 1992 Peter Edward Cann, all rights reserved.
  2.  *    MicroSoft QuickC
  3.  */
  4.  
  5. #include<stdio.h>
  6. #include<bios.h>
  7. #include<dos.h>
  8. #include<fcntl.h>
  9. #include<sys\types.h>
  10. #include<sys\stat.h>
  11. #include<signal.h>
  12. #include<process.h>
  13. #include"port.h"
  14.  
  15. sendchar(c)
  16.     unsigned char c;
  17.     {
  18.     while(!((inp(basereg+STATREG)&TXMTMASK)&&(inp(basereg+MSTATREG)&CTSMASK)))
  19.         if(kbhit())
  20.             getch();
  21.     outp(basereg, c);
  22.     }
  23.  
  24. int follow;
  25.  
  26. quit()
  27.     {
  28.     cleanup(0);
  29.     exit(99);
  30.     }
  31.  
  32. sendstr(str)
  33.     char *str;
  34.     {
  35.     int i;
  36.     for(i=0;str[i]!='\0';++i)
  37.         if(str[i]=='\n')
  38.             {
  39.             sendchar('\r');
  40.             sendchar('\n');
  41.             }
  42.         else
  43.             sendchar(str[i]);
  44.     }
  45.  
  46. portgets(str)
  47.     char *str;
  48.     {
  49.     int i;
  50.     i=0;
  51.     while(i<255)
  52.         {
  53.         while(follow==index)
  54.             {
  55.             if(!(inp(basereg+MSTATREG)&DCDMASK))
  56.                 return(-1);
  57.             if(kbhit())
  58.                 getch();
  59.             }
  60.         str[i]=buf[follow++];
  61.         if(str[i]=='\b')
  62.             if(i>0)
  63.                 {
  64.                 i-=2;
  65.                 sendchar('\b');
  66.                 sendchar(' ');
  67.                 sendchar('\b');
  68.                 }
  69.             else
  70.                 {
  71.                 i--;
  72.                 sendchar(0x07);
  73.                 }
  74.         else
  75.             sendchar(str[i]);
  76.         follow%=TBUFSIZ;
  77.         if((str[i]=='\r')||(str[i]=='\n'))
  78.             {
  79.             sendchar('\r');
  80.             sendchar('\n');
  81.             str[i]='\0';
  82.             break;
  83.             }
  84.         i++;
  85.         }
  86.     str[255]='\0';
  87.     return(0);
  88.     }
  89.         
  90. main(argc, argv)
  91.     int argc;
  92.     char **argv;
  93.     {
  94.     FILE *fd;
  95.     long timestamp;
  96.     int i, j, outfd, ok, c, run, result;
  97.     char str[256], filename[256], str1[256];
  98.     index=follow=0;
  99.     printf("Copyright (C) 1992 Peter Edward Cann, all rights reserved.\n");
  100.     if(!strcmp(getenv("REMOTE"), "YES"))
  101.         {
  102.         printf("You appear to be already logged in remotely, judging by the environment\n");
  103.         printf("variable REMOTE, so this is probably a very bad idea.\n");
  104.         printf("Are you sure you want to run MESSIN? (y or n) --> ");
  105.         if(getchar()!='y') /* Note getchar() and not getch()! */
  106.             {
  107.             printf("I didn't think so!\n");
  108.             exit(99);
  109.             }
  110.         else
  111.             printf("OK, you're the boss!");
  112.         }
  113.     printf("Control-C to Exit.\n");
  114.     if(argc!=4)
  115.         {
  116.         printf("USAGE: messin <comnum> <bps> <directory>\n");
  117.         exit(1);
  118.         }
  119.     comnum=atoi(argv[1])-1;
  120.     speed=atoi(argv[2]);
  121.     databits='8';
  122.     parity='n';
  123.     stopbits='1';
  124.     setport();
  125.     readset();
  126.     setup();
  127.     signal(SIGINT, quit);
  128.     sprintf(str, "\nEnter your account name: --> ");
  129.     sendstr(str);
  130.     if(portgets(str)==-1)
  131.         {
  132.         printf("Lost carrier detect.\n");
  133.         exit(10);
  134.         }
  135.     for(i=(strlen(str)-1);i>=0;i--)
  136.         if(str[i]=='\\')
  137.             {
  138.             sprintf(str, "Backslash is not permitted!\n");
  139.             sendstr(str);
  140.             exit(11);
  141.             }
  142.     sprintf(filename, "%s\\%s", argv[3], str);
  143.     if((fd=fopen(filename, "r"))==NULL)
  144.         {
  145.         sprintf(str, "Sorry, can't open the file.\n");
  146.         sendstr(str);
  147.         printf("Error opening MESSIN file.\n");
  148.         exit(1);
  149.         }
  150.     i=0;
  151.     while(1)
  152.         {
  153.         i++;
  154.         if(fgets(str, 80, fd)==NULL)
  155.             {
  156.             sprintf(str, "*** END OF MESSAGE ***\n\n");
  157.             sendstr(str);
  158.             exit(0);
  159.             }
  160.         sendstr(str);
  161.         if(!(i%20))
  162.             {
  163.             sprintf(str, "PRESS ANY KEY TO CONTINUE: --> ");
  164.             sendstr(str);
  165.             while(index==follow);
  166.             follow=index;
  167.             sprintf(str, "\n");
  168.             sendstr(str);
  169.             }
  170.         }
  171.     exit(0);
  172.     }
  173.